<!-- 当前页面为文档模块入口，当列表打开’查看文档‘时，所有内容在此 -->
<template>
	<div>
		<el-tabs v-model="activeName">
			<el-tab-pane v-for="(item, index) in tabsList" :key="index" :label="item.label" :name="item.value" @tab-click="handleTabChange"> </el-tab-pane>

			<div class="content-card">
				<html-label :title="activeLabelTitle">
					<div
						v-if="
							!(nowRowData.dataStatus && nowRowData.dataStatus !== '0') &&
							['BaseDetail', 'Extend', 'ObjectOther', 'OperationsRecords1'].includes(activeName)
						"
					>
						<!-- <el-button v-auth="[nowRowData.isOperate == 1, baseConfig.auth.edit]" type="primary" plain @click="handleOperate('rechange')">
							信息变更
						</el-button> -->
					</div>
				</html-label>

				<component
					v-if="!loading"
					class="pd10"
					:is="whickComm[activeName]"
					:isWithAuth="0"
					:soleKey="`dpServiceFacility-${nowRowData.soleValue}`"
					@refresh="handleRefresh"
					:nowRowData="nowRowData"
				></component>
			</div>
		</el-tabs>
	</div>
</template>

<script setup lang="ts">
import Extend from './Extend/index.vue'
import BaseDetail from './BaseDetail/index.vue'
import ObjectOther from './ObjectOther/index.vue'
import OperationsRecords from './OperationsRecords/index.vue'
import ReviewRecord from './ReviewRecord/index.vue'
import PractitionersPersonnel from './PractitionersPersonnel/index.vue'
import LevelRating from './LevelRating/index'
import ServiceManagement from './ServiceManagement/index.vue'
import ChainBlockInfo from './ChainBlockInfo/index.vue'
// import SubsidyManagement from './SubsidyManagement/index.vue'
import DataChangeLog from '@/views/datacenter/components/DataChangeLog/index.vue'
import OperationsRecords1 from './OperationsRecords1/index.vue'
import VideoMonitor from './VideoMonitor/index.vue'
import apiMod from '@/apiMod'
import { baseConfig } from '../../config'
import { useOperate } from '@/views/datacenter/hooks/useConfig'
import { useCommonStore } from '@/stores/common'
import bus from '@/utils/eventbus'

const { setTempParams, setLoading, setMoreSearch } = useCommonStore()
const { onDelete, onMessageChange } = useOperate(3)

const whickComm = {
	BaseDetail,
	Extend,
	ObjectOther,
	OperationsRecords,
	ReviewRecord,
	PractitionersPersonnel,
	LevelRating,
	ServiceManagement,
	// SubsidyManagement,
	OperationsRecords1,
	DataChangeLog,
	ChainBlockInfo,
	VideoMonitor,
}
type Props = {
	nowRowData?: any
}
const props = withDefaults(defineProps<Props>(), {})
const emit = defineEmits(['refresh', 'rechange'])
const loading = ref(false)
const activeLabelTitle = ref('基础信息')

const tabs = {
	base: [
		{ label: '基础信息', value: 'BaseDetail' },
		{ label: '扩展信息', value: 'Extend' },
		{ label: '其他信息', value: 'ObjectOther' },
		{ label: '视频监控信息', value: 'VideoMonitor' },
		// { label: '运营记录', value: 'OperationsRecords' },
		{ label: '运营记录', value: 'OperationsRecords1' },
		{ label: '等级评定档案', value: 'LevelRating' },
		{ label: '社区养老服务管理', value: 'ServiceManagement' },
	],
	community: [
		{ label: '从业人员', value: 'PractitionersPersonnel' },
		{ label: '信息编辑记录', value: 'DataChangeLog' },
		{ label: '上链信息', value: 'ChainBlockInfo' },
	],
	institute: [
		// { label: '年审记录', value: 'ReviewRecord' },
		// { label: '补贴管理', value: 'SubsidyManagement' },
	],
}
const tabsList: any = [...tabs.base, ...tabs['institute'], ...tabs['community']]
const activeName = ref('BaseDetail')
let nowData = ref({})
provide('nowRowData', nowData)
const getInitData = () => {
	loading.value = true
	setLoading()
	apiMod
		.dpServiceFacility_details(props.nowRowData.soleValue)
		.then((res) => {
			loading.value = false
			nowData.value = res.data || {}
			setLoading()
		})
		.catch((err) => {
			loading.value = false
		})
}

setMoreSearch({
	params: {
		soleValue: props.nowRowData.soleValue,
	},
})

const openEdit = () => {
	onMessageChange().then(() => {
		const activeStr = {
			BaseDetail: 1,
			Extend: 2,
			ObjectOther: 3,
			OperationsRecords1: 4,
		}
		setTempParams({
			name: props.nowRowData.soleValue,
			active: activeStr[activeName.value] || 1,
		})
		emit('rechange', 'Rechange', props.nowRowData, '信息变更数据')
	})
}

const handleOperate = (type) => {
	if (type == 'delete') {
		onDelete([props.nowRowData[baseConfig.rowKey]], baseConfig.api.delete, props.nowRowData.soleValue).then(() => {
			emit('refresh')
		})
		return
	}
	openEdit()
}
const handleTabChange = (tab) => {
	activeLabelTitle.value = tab.props.label
}

bus.on('menu-operate', (res) => {
	if (res.pageName == baseConfig.pageName) {
		handleOperate(res.operate)
	}
})

const handleRefresh = () => {
	emit('refresh')
}
onMounted(() => {
	getInitData()
})

onUnmounted(() => {
	setMoreSearch({})
})
</script>

<style scoped></style>
